IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_sp_EntityMetaFieldGetByName]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[cms_sp_EntityMetaFieldGetByName]
GO
create procedure [dbo].[cms_sp_EntityMetaFieldGetByName]
@MetaFieldName nvarchar(250),
@MetaFieldType nvarchar(400),
@EntityType nvarchar(400) = null
as
select 
	EntityMetaFields.EntityMetaFieldId,
	EntityMetaFieldLinks.EntityMetaFieldLinkId,
	EntityMetaFields.MetaFieldName,
    EntityMetaFields.MetaFieldDescription,
	EntityMetaFields.IsSystem,
    EntityMetaFields.MetaFieldType
from dbo.EntityMetaFields
inner join dbo.EntityMetaFieldLinks
	on EntityMetaFieldLinks.EntityMetaFieldId = EntityMetaFields.EntityMetaFieldId
where EntityMetaFields.MetaFieldName = @MetaFieldName and EntityMetaFields.MetaFieldType = @MetaFieldType and
	(EntityMetaFieldLinks.EntityTypeParameter = @EntityType or @EntityType is null)


GO

